<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.mselect.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.multiselect.js"></script>
<style type="text/css">
.more_status {
	position: absolute;
	top: 16px;
	left: 2px;
	width: 55px;
	background-color: #eeeeee;
	z-index: 100;
	display: none;
	border: 1px solid;
}
#sortable1 {list-style-type: none; margin: 0; padding: 0; float: left; margin-right: 50px; background: #eee; padding: 5px; width: 100px; height: auto;}
ul .ui-state-highlight { margin: 3px; padding: 3px; font-size: 1em; font-color: orange; width: 85px; }
#sortable1 li {font-size: 15px; padding: 4px 0;}
</style>
<script type="text/javascript">
get_check = function(){
	var ids = '';
	$("#list").find("input[type='checkbox']").each(function(){
		if ($(this).is(":checked"))
		{
			if (ids)
			{
				ids += ',';
			}
			ids += $(this).val();
		}
	});
	return ids;
};
$(function(){
	$(".wrong_log").colorbox({width:"50%", height:"40%", iframe:true});
	$("#shop_ids, #site ,#folder_ids, #multi_copy_shop_ids").multiselect({height: 260, minWidth: 160});
	$("#date").datepicker({dateFormat: 'yy-mm-dd', changeMonth: true, minDate: 0});
	$(".datepicker").datepicker({dateFormat: 'yy-mm-dd', changeMonth: true});
	$(".gallery-pic").colorbox({slideshow:true, slideshowAuto: false, maxWidth: '90%', maxHeight: '90%'});
	$("#dialog_set_schedule").dialog({autoOpen:false, modal:true, width: 800, height: 200});
	$("#dialog_move_to_folder").dialog({autoOpen:false, modal:true, width: 350, height: 400});
	$("#dialog_multi_copy").dialog({autoOpen:false,modal:true, height: 300, width: 300});
	$(".more_click").mouseover(function(){
		$(this).next().show();
	}).mouseout(function(){
		$(this).next().hide();
	});
	$(".more_content").mouseover(function(){
		$(this).show();
	}).mouseout(function(){
		$(this).hide();
	});
	$("#check_all").click(function(){if ($(this).is(":checked")){$("#list input[type='checkbox']").attr("checked", true);}else{$("#list input[type='checkbox']").attr("checked", false);}});
	$("#multi_push_btn").click(function(){
		var ids = get_check();
		if ( ! ids)
		{
			alert('请选择listing');
			return false;
		}
		if (confirm("确定推送所选中listing"))
		{
			$("#action_form_ids").val(ids);
			$("#action_form").attr("action", "<?=url('Online::EbayListing/Push')?>").submit();
		}
	});
	$("#multi_del_btn").click(function(){
		var ids = get_check();
		if ( ! ids)
		{
			alert('请选择listing');
			return false;
		}
		if (confirm("确定删除所选中listing"))
		{
			$("#action_form_ids").val(ids);
			$("#action_form").attr("action", "<?=url('Online::EbayListing/Delete')?>").submit();
		}
	});
	$("#multi_schedule_btn").click(function(){
		var ids = get_check();
		if ( ! ids)
		{
			alert("请选择listing");
			return false;
		}
		$("#schedule_listing_id").val(ids);
		$("#dialog_set_schedule").dialog("open");
	});
	$("#multi_folder_btn").click(function(){
		var ids = get_check();
		if ( ! ids)
		{
			alert("请选择listing");
			return false;
		}
		$("#folder_listing_id").val(ids);
		$("#dialog_move_to_folder").dialog("open");
	});
	$(".multi_copy_click").click(function(){
		$("#multi_copy_id").val($(this).next().val());
		$("#dialog_multi_copy").dialog("open");
	});
	$("#multi_copy_btn").click(function(){
		window.open("<?=url('Online::EbayListing/MultiCopy')?>&id=" + $("#multi_copy_id").val() + "&shop_ids=" + $("#multi_copy_shop_ids").val() + "&folder_id=" + $("#multi_copy_folder_id").val());
	});
	$(".delete").click(function(){if ( ! confirm('确定删除Listing？'))return false;});
});
</script>
<style>
.more_content {
	position: absolute;
	top: 15px;
	left: 25px;
	width: 50px;
	background-color: #eeeeee;
	z-index: 100;
	display: none;
	border: 1px solid;
}
</style>
<fieldset><legend>查询条件</legend>
<form method="get" action="">
<?include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table" >
<tr>
	<th>Folder</th>
	<td>
		<select name="folder_ids[]"  multiple="multiple" id="folder_ids">
			<?foreach ($folder as $s):?>
			<option value="<?=$s['id']?>" <?if (isset($_GET['folder_ids']) && in_array($s['id'], $_GET['folder_ids'])):?>selected="selected"<?endif;?>><?=$s['name']?></option>
			<?endforeach;?>
		</select>
		<a href="<?=url('Online::EbayListing/FolderList')?>" class="folder">Manage Folders</a>
	</td>
</tr>
<tr>
	<th>店铺</th>
	<td>
		<select name="shop_ids[]" multiple="multiple" id="shop_ids">
			<?foreach ($shop as $s):?>
			<option value="<?=$s['id']?>" <?if (isset($_GET['shop_ids']) && in_array($s['id'], $_GET['shop_ids'])):?>selected="selected"<?endif;?>><?=$s['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>站点</th>
	<td>
		<select name="site[]" multiple="multiple" id="site">
			<?foreach (Q::ini('custom_flag/online_ebay_listing_site') as $oels):?>
			<option value="<?=$oels['value']?>" <?if (isset($_GET['site']) && in_array($oels['value'], $_GET['site'])):?>selected="selected"<?endif;?>><?=$oels['name']?> - <?=$oels['value']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>SKU</th>
	<td><input type="text" name="sku" value="<?=isset($_GET['sku']) ? $_GET['sku'] : ''?>" size="60"/><br/>说明：多个sku请用英文逗号分开</td>
</tr>
<tr>
	<th>周期</th>
	<td>
		<?foreach (Q::ini('custom_flag/online_ebay_listing_duration_search') as $d):?>
		<label><input type="checkbox" name="listing_duration[]" value="<?=$d?>" <?if (isset($_GET['listing_duration']) && in_array($d, $_GET['listing_duration'])):?>checked="checked"<?endif;?> /><?=$d?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th>类型</th>
	<td colspan="3">
		<?foreach (Q::ini('custom_flag/online_ebay_listing_type') as $oelt):?>
		<label><input type="checkbox" name="listing_type[]" value="<?=$oelt['value']?>" <?if (isset($_GET['listing_type']) && in_array($oelt['value'], $_GET['listing_type'])):?>checked="checked"<?endif;?> /><?=$oelt['name']?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th>多数量</th>
	<td colspan="3">
		<?foreach (Q::ini('custom_flag/online_ebay_listing_variation') as $oelv):?>
		<label><input type="checkbox" name="variation[]" value="<?=$oelv['value']?>" <?if (isset($_GET['variation']) && in_array($oelv['value'], $_GET['variation'])):?>checked="checked"<?endif;?> /><?=$oelv['name']?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th>状态</th>
	<td>
		<?foreach (Q::ini('custom_flag/ebay_listing_push_flag') as $elpf):?>
		<label><input type="checkbox" name="push_flag[]" value="<?=$elpf['value']?>" <?if (isset($_GET['push_flag']) && in_array($elpf['value'], $_GET['push_flag'])):?>checked="checked"<?endif;?> /><?=$elpf['name']?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th>Schedule</th>
	<td>
		<?foreach (Q::ini('custom_flag/online_ebay_listing_schedule_flag') as $oelsf):?>
		<label><input type="checkbox" name="schedule_flag[]" value="<?=$oelsf['value']?>" <?if (isset($_GET['schedule_flag']) && in_array($oelsf['value'], $_GET['schedule_flag'])):?>checked="checked"<?endif;?> /><?=$oelsf['name']?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th>Repeat</th>
	<td>
		<?foreach (Q::ini('custom_flag/online_ebay_listing_schedule_repeat') as $oelsr):?>
		<label><input type="checkbox" name="schedule_repeat[]" value="<?=$oelsr['value']?>" <?if (isset($_GET['schedule_repeat']) && in_array($oelsr['value'], $_GET['schedule_repeat'])):?>checked="checked"<?endif;?> /><?=$oelsr['name']?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th>RepeatDays</th>
	<td>
		<select name="schedule_repeat_step_operator">
			<option value="">请选择..</option>
			<option value="=" <?if (isset($_GET['schedule_repeat_step_operator']) && $_GET['schedule_repeat_step_operator'] == '=')echo "selected='selected'"?>>=</option>
			<option value=">=" <?if (isset($_GET['schedule_repeat_step_operator']) && $_GET['schedule_repeat_step_operator'] == '>=')echo "selected='selected'"?>>>=</option>
			<option value="<=" <?if (isset($_GET['schedule_repeat_step_operator']) && $_GET['schedule_repeat_step_operator'] == '<=')echo "selected='selected'"?>><=</option>
		</select>
		<input type="text" name="schedule_repeat_step" value="<?=isset($_GET['schedule_repeat_step']) ? $_GET['schedule_repeat_step'] : ''?>" />
	</td>
</tr>
<tr>
	<th>创建时间</th>
	<td>
		<input type="text" name="begin_create_time" value="<?=isset($_GET['begin_create_time']) ? $_GET['begin_create_time'] : ''?>" class="datepicker" /> to
		<input type="text" name="end_create_time" value="<?=isset($_GET['end_create_time']) ? $_GET['end_create_time'] : ''?>" class="datepicker" />
	</td>
</tr>
<tr>
	<th>创建人</th>
	<td><input type="text" name="create_user_name" value="<?=isset($_GET['create_user_name']) ? $_GET['create_user_name'] : ''?>" /></td>
</tr>
<tr>
	<td></td>
	<td><input type="submit" value="查询" class="button" /></td>
</tr>
</table>
</form></fieldset>

<table class="list_table" style="table-layout: fixed;" width="98%" id="list">
<tr>
	<th width="20"></th>
	<th width="130">店铺</th>
	<th width="80">站点</th>
	<th>标题</th>
	<th width="60">周期</th>
	<th width="50">图片</th>
	<th width="70">价格</th>
	<th width="80">创建</th>
	<th width="80">操作</th>
</tr>
<?foreach ($listing as $l):?>
<tr>
	<td><input type="checkbox" value="<?=$l['id']?>" /></td>
	<td><?=$l['shop_name']?></td>
	<td><?=$l['site']?></td>
	<td align="left" class="overflow-hidden" title="<?=htmlspecialchars($l['title'])?>">
		<?if ($l['view_url']):?>
		<a href="<?=$l['view_url']?>" target="_blank"><?=$l['title']?></a>
		<?else:?>
		<?=$l['title']?>
		<?endif;?>
		<br />
		<span class="<?=Helper_BSS_Normal::getIniOne('online_ebay_listing_type', 'value', $l['listing_type'], 'icon_class')?> <?=Helper_BSS_Normal::getIniOne('online_ebay_listing_variation', 'value', $l['variation'], 'icon_class')?>"></span>
		<?if ($l['push_flag'] == Q::ini('custom_flag/ebay_listing_push_flag/flag/value')):?><a class="wrong_log" href="<?=url('Online::EbayListing/ScheduleWrongDetail', array('id' => $l['id']))?>"><span title="push" class="listing_push_icon"></span></a><?endif;?>
		<?if ($l['schedule_flag'] == Q::ini('custom_flag/online_ebay_listing_schedule_flag/set/value')):?><span title="schedule time:<?=$l['schedule_next_time']?>" class="lisiting_schedule_icon"></span><?endif;?>
		<?if ($l['schedule_flag'] == Q::ini('custom_flag/online_ebay_listing_schedule_flag/wrong/value')):?><a class="wrong_log" href="<?=url('Online::EbayListing/ScheduleWrongDetail', array('id' => $l['id']))?>"><span title="schedule wrong" class="lisiting_schedule_wrong_icon"></span></a><?endif;?>
		<?if ($l['schedule_repeat'] == Q::ini('custom_flag/online_ebay_listing_schedule_repeat/repeat/value')):?><span title="schedule_repeat:<?=$l['schedule_repeat_step']?> Days" class="listing_schedule_repeat_icon"></span><?endif;?>
	</td>
	<td><?=$l['listing_duration']?></td>
	<td><?if ($l['gallery_picture_url']):?><a href="<?=$l['gallery_picture_url']?>" class="gallery-pic"><img src="<?=$l['gallery_picture_url']?>" width="40px" height="40px" /></a><?endif;?></td>
	<td><?=$l['currency_code']?> <?=$l['start_price']?></td>
	<td><?=$l['create_user_name']?><br /><?=substr($l['create_time'], 0, 10)?></td>
	<td>
		<div style="float: right; position: relative;">
			<a href="<?=url('Online::EbayListing/Edit', array('id' => $l['id']))?>" target="_blank">编辑</a>
			<a class="more_click">更多&or;</a>
			<ul class="more_content">
				<li><a href="<?=url('Online::EbayListing/Copy', array('id' => $l['id']))?>" target="_blank">复制</a></li>
				<li><a class="multi_copy_click">批量复制</a><input type="hidden" value="<?=$l['id']?>" /></li>
				<li><a href="<?=url('Online::EbayListing/Delete', array('ids' => $l['id']))?>" class="delete">删除</a></li>
			</ul>
		</div>
	</td>
</tr>
<?endforeach;?>
</table>
<?=$page?>
<table class="list_table">
<tr>
	<td rowspan="3"><label><input type="checkbox" id="check_all" />全选</label></td>
	<td>
		<input type="button" value="批量推送" class="button" id="multi_push_btn" /> | 
		<input type="button" value="批量schedule" class="button" id="multi_schedule_btn" /> | 
	</td>
	<td>
		<input type="button" value="文件夹移动" class="button" id="multi_folder_btn" /> | 
	</td>
	<td>
		<input type="button" value="批量删除" class="button" id="multi_del_btn" /> 
	</td>
</tr>
</table>
<form action="" method="post" id="action_form">
<input type="hidden" name="ids" value="" id="action_form_ids" />
<input type="hidden" name="param1" value="" id="param1" />
<input type="hidden" name="<?=Q::ini('unique_token_name')?>" value="<?=Helper_BSS_Normal::genToken()?>" />
</form>

<div id="dialog_set_schedule" title="批量设置Schedule">
<form method="post" action="<?=url('Online::EbayListing/SetSchedule')?>">
	<input type="hidden" name="ids" id="schedule_listing_id" value="" />
	<table class="form_table">
	<tr>
		<th>Schedule Time</th>
		<td>
		<div id="schedule_div">
			<input name="date" id="date" value="" class="datepicker" /> /&nbsp;
			<select id="hour" name="hour">
					<?for ($i = 0; $i < 24; $i++):?>
					<option value="<?=str_pad($i, 2, 0, STR_PAD_LEFT)?>"><?=str_pad($i, 2, 0, STR_PAD_LEFT)?></option>
					<?endfor;?>
			</select> 时 :
			<select id="minute" name="minute">
					<?for ($j = 0; $j < 60; $j++):?>
					<option value="<?=str_pad($j, 2, 0, STR_PAD_LEFT)?>"><?=str_pad($j, 2, 0, STR_PAD_LEFT)?></option>
					<?endfor;?>
			</select> 分  =>
			<label>Timezone</label>
			<select id="timezone" name="timezone">
					<?foreach (Q::ini('custom_flag/timezone') as $z):?>
					<option value="<?=$z['value']?>" ><?=$z['name']?></option>
					<?endforeach;?>
			</select>
			<span id="show_time"></span>
		</div>
		</td>
	</tr>
	<tr>
		<th>Each listing interval</th>
		<td><input name="interval_minute" />minutes</td>
	</tr>
	<tr>
		<th><input type="checkbox" id="schedule_repeat" name="schedule_repeat" <?=isset($listing['schedule_repeat']) ? 'checked="checked"' : ""?>"/>Repeat Duration</th>
		<td>
			<input id="schedule_repeat_step" name="schedule_repeat_step" value="<?=isset($listing['schedule_repeat_step']) ? $listing['schedule_repeat_step'] : ''?>" />Days
		</td>
	</tr>
	<tr>
		<th></th>
		<td>
			<input type="submit" class="button" value="确定"/>
		</td>
	</tr>
	</table>
</form>
</div>

<div id="dialog_move_to_folder" title="please choose folder">
<form method="post" action="<?=url('Online::EbayListing/MoveToFolder')?>">
	<input type="hidden" name="ids" id="folder_listing_id" value="" />
	<div style="margin:20px">
	<ul id="sortable1" title="">
		<?foreach ($folder as $k => $f):?>
			<li><label><input type="radio" name="folder_id" value="<?=$f['id']?>" /><?=$f['name']?></label></li>
		<?endforeach;?>
	</ul>
		<input type="submit" class="button" value="确定" />
	</div>
</form>
</div>

<div id="dialog_multi_copy" title="批量复制">
<table class="form_table">
<tr>
	<th>店铺</th>
	<td>
		<select name="shop_ids[]" multiple="multiple" id="multi_copy_shop_ids">
			<?foreach ($shop as $s):?>
			<option value="<?=$s['id']?>"><?=$s['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>Folder</th>
	<td>
		<select name="folder_id" id="multi_copy_folder_id">
			<option value="">请选择</option>
			<?foreach ($folder as $s):?>
			<option value="<?=$s['id']?>"><?=$s['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
</table>
<br />
<div align="center">
<input type="button" class="button" id="multi_copy_btn" value="确定" />
<input type="hidden" id="multi_copy_id" value="" />
</div>
</div>
<?php $this->_endblock();?>